import java.util.Stack;

/**
 * @program: LeetCode
 * @description: LeetCode :  232.两个栈组成队列
 * @author: WXY
 * @create: 2023-01-16 09:41
 * @Version 1.0
 **/
public class Num232_MyQueue {

    class MyQueue {
        Stack<Integer> stackIn;
        Stack<Integer> stackOut;

        public MyQueue() {
            stackIn = new Stack<>();
            stackOut = new Stack<>();
        }

        public void push(int x) {
            stackIn.push(x);
        }

        public int pop() {
            if (stackOut.isEmpty()) {
                while (!stackIn.isEmpty()) {
                    stackOut.push(stackIn.pop());
                }
            }
            int res = stackOut.pop();
            return res;
        }

        public int peek() {
            if (stackOut.isEmpty()) {
                while (!stackIn.isEmpty()) {
                    stackOut.push(stackIn.pop());
                }
            }
            int res = stackOut.peek();
            return res;
        }

        public boolean empty() {
            return stackOut.isEmpty() && stackIn.isEmpty();
        }
    }
}
